home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Internet Time / InternetTime.jar / InternetTime$InternetTimeDisplay.class (.txt) < prev   
Encoding:
Java Class File  |  2001-08-31  |  3.0 KB  |  95 lines

  1. import javax.microedition.lcdui.Canvas;
  2. import javax.microedition.lcdui.Font;
  3. import javax.microedition.lcdui.Graphics;
  4.  
  5. class InternetTime$InternetTimeDisplay extends Canvas implements Runnable {
  6.    private static final long MILLIS_IN_DAY = 86400000L;
  7.    private static final long MILLIS_IN_BEAT = 86400L;
  8.    private Thread thread;
  9.    private int width;
  10.    private int height;
  11.    private int xStr;
  12.    private int yStr;
  13.    private long timeMs;
  14.    private long timeBeats;
  15.    private boolean goOn;
  16.    private int beatsCounter;
  17.    private long msCounter;
  18.    private long msWhenStart;
  19.    private Font defaultFont;
  20.    // $FF: synthetic field
  21.    private final InternetTime this$0;
  22.  
  23.    InternetTime$InternetTimeDisplay(InternetTime this$0) {
  24.       this.this$0 = this$0;
  25.       this.width = ((Canvas)this).getWidth();
  26.       this.height = ((Canvas)this).getHeight();
  27.       this.xStr = this.width / 2;
  28.       this.yStr = this.height / 2;
  29.       this.defaultFont = Font.getFont(64, 1, 16);
  30.    }
  31.  
  32.    public void run() {
  33.       long delta = 0L;
  34.       this.beatsCounter = 0;
  35.       this.msCounter = 0L;
  36.  
  37.       for(this.msWhenStart = System.currentTimeMillis(); this.goOn; delta = System.currentTimeMillis() - this.msWhenStart - (long)this.beatsCounter * 86400L) {
  38.          ((Canvas)this).repaint();
  39.          ++this.beatsCounter;
  40.          ++this.timeBeats;
  41.          if (this.timeBeats == 1000L) {
  42.             this.timeBeats = 0L;
  43.          }
  44.  
  45.          try {
  46.             Thread.sleep(86400L - delta);
  47.          } catch (Exception var4) {
  48.             ((Throwable)var4).printStackTrace();
  49.          }
  50.       }
  51.  
  52.    }
  53.  
  54.    void setTimeMs(long value) {
  55.       this.timeMs = value;
  56.       this.timeMs %= 86400000L;
  57.       this.timeBeats = this.timeMs / 86400L;
  58.       this.restartThread();
  59.    }
  60.  
  61.    long getTimeMs() {
  62.       return this.timeBeats * 86400L;
  63.    }
  64.  
  65.    void restartThread() {
  66.       if (this.thread != null) {
  67.          this.stopThread();
  68.       }
  69.  
  70.       this.startThread();
  71.    }
  72.  
  73.    void startThread() {
  74.       this.goOn = true;
  75.       this.thread = new Thread(this);
  76.       this.thread.start();
  77.    }
  78.  
  79.    void stopThread() {
  80.       this.goOn = false;
  81.       if (this.thread != null) {
  82.          this.thread = null;
  83.       }
  84.  
  85.    }
  86.  
  87.    public void paint(Graphics g) {
  88.       g.setColor(0);
  89.       g.fillRect(0, 0, this.width, this.height);
  90.       g.setColor(16777215);
  91.       g.setFont(this.defaultFont);
  92.       g.drawString("@ " + this.timeBeats, this.xStr, this.yStr, 65);
  93.    }
  94. }
  95.